<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
    <%@include file="../includes/common.jsp" %>
    <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
    <%@ page contentType="text/html;charset=UTF-8" %>

    <title>好友界面</title>
</head>
<body>
<div class="container-fluid" style="padding: 0">
    <div class="row-fluid">

        <div style="padding: 10px">
            <form class="form-inline">
                输入账号：<input type="text" class="input-medium" name="loginName" id="loginName"  value=""/>

                <a class="btn btn-primary" onclick="query()">查找</a>
                <a class="btn btn-primary" onclick="addFriend()">添加关注</a>
            </form>
            <table id="dataTable"></table>

            <div id="dataEdit" closed="true" modal="true" style="overflow: hidden" closable="true">
                <iframe style="width: 100%;height: 100%"
                        id="contentFrame"
                        name="contentFrame"
                        marginheight="0"
                        marginwidth="0"
                        frameborder="0" src=""
                        allowTransparency="true">
                </iframe>
            </div>

        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">

    function query() {
        listOption.url = basePath+"consumer/findAllFriend";
        listOption.data = "loginName="+$("#loginName").val().trim();
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title: "关注的人",
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'loginName', title: '用户名', sortable: true, align: 'center', width: 300},
                    {field: 'showSex', title: '性别', align: 'center', width: 200},
                    {field: 'birthday', title: '生日', align: 'center', width: 200},
                    {field: 'email', title: '邮箱', align: 'center', width: 200},
                    {field: 'city', title: '城市', align: 'center', width: 200},
                    {field: 'edit', title: '操作', align: 'center', width: 200}
                ]
            ],
            sortName: "",
            sortOrder: "",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "loginName":
                sortColumn = "login_name";
                break;

        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }


    function delFriend(id) {
        $.messager.confirm("提示", "确认删除？", function (r) {
            if (r) {
                $.ajax({
                    url: basePath + "consumer/delFriend?id=" + id,
                    dataType: "json",
                    type: "DELETE",
                    success: function () {
                        $.messager.alert("成功", "删除成功！", "", function () {
                            query();
                        })
                    },
                    error: doError
                })
            }
        })
    }
    function queryFormat(temp) {
        var rowDataList = [];
        for (var i in temp) {
            idBtn = "&nbsp;<input type='checkbox' name='deleteUserCheckBox' id='" + temp[i].id + "' value='" + temp[i].id + "'\">&nbsp;";
            editBtn = "&nbsp;<a onclick='delFriend(\"" + temp[i].id + "\")'>删除</a>&nbsp;";
            temp[i].id = idBtn;
            temp[i].edit = editBtn;
            rowDataList.push(temp[i]);
        }
        return rowDataList;
    }

    function addFriend() {
        $("#contentFrame")[0].contentWindow.document.write("");
        $("#contentFrame").attr("src", basePath + "consumer/addFriendDo");
        $('#dataEdit').dialog({
            title: '查找',
            height: 400,
            width: 600
        })
        $('#dataEdit').dialog('open');
    }


    $(function () {
        initDataGrid();
        query();
    });
</script>